/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufrpe.bsi.pvs.view.assistant;

import java.awt.Color;
import java.awt.Dimension;
import java.util.List;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;

import br.ufrpe.bsi.pvs.Fachada;
import br.ufrpe.bsi.pvs.model.roupa.Roupa;
import br.ufrpe.bsi.pvs.view.PvsFrame;
import br.ufrpe.bsi.pvs.view.renders.TableHeaderRenderer;
import javax.swing.ImageIcon;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import java.awt.Font;

public class TelaResultados extends javax.swing.JPanel {

	public static final TelaResultados INSTANCE = new TelaResultados();

	/**
	 * Creates new form TelaResultados
	 * 
	 * @param listaRoupa
	 * @param List
	 * @param roupas
	 * @param Roupa
	 */
	private TelaResultados() {
		initComponents();
		renderTable();
	}

	public void carregarTabela(List<Roupa> listaRoupa) {
		jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1,
				1, 1, 1));

		tbRoupas.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N

		String colunas[] = { "ID", "Descricao", "Tamanho", "Estilo",
				"Tipo Roupa", "Estocados", };

		Object tabela[][] = new Object[listaRoupa.size()][colunas.length];

		int i = 0;
		for (Roupa r : listaRoupa) {
			tabela[i][0] = r.getId();
			tabela[i][1] = r.getDescricao();
			tabela[i][2] = r.getTamanho().getTamanho();
			tabela[i][3] = r.getEstilo().getNomeEstilo();
			tabela[i][4] = r.getTipoRoupa().getNome();
			tabela[i][5] = r.getQuantEstoque();
			i++;
		}

		TableModel tm = new DefaultTableModel(tabela, colunas);
		tbRoupas.setModel(tm);

		// tbRoupas.setModel(new javax.swing.table.DefaultTableModel(
		// new Object[][] { { null, null, null, null, null, null, null },
		// { null, null, null, null, null, null, null },
		// { null, null, null, null, null, null, null },
		// { null, null, null, null, null, null, null } }, colunas)
		{
			boolean[] canEdit = new boolean[] { false, true, true, true, true,
					true, true };

			// boolean isCellEditable(int rowIndex, int columnIndex) {
			// return canEdit[columnIndex];
			// }
		}
		;

		jScrollPane1.setViewportView(tbRoupas);
		if (tbRoupas.getColumnModel().getColumnCount() > 0) {
			tbRoupas.getColumnModel().getColumn(0).setResizable(false);
			tbRoupas.getColumnModel().getColumn(1).setResizable(false);
			tbRoupas.getColumnModel().getColumn(2).setResizable(false);
			tbRoupas.getColumnModel().getColumn(3).setResizable(false);
			tbRoupas.getColumnModel().getColumn(4).setResizable(false);
			tbRoupas.getColumnModel().getColumn(5).setResizable(false);
		}
	}

	private void renderTable() {
		tbRoupas.setTableHeader(new JTableHeader(tbRoupas.getColumnModel()) {
			@Override
			public Dimension getPreferredSize() {
				Dimension d = super.getPreferredSize();
				d.height = 28;
				return d;
			}
		});
		tbRoupas.getTableHeader().setDefaultRenderer(new TableHeaderRenderer());
		tbRoupas.setRowHeight(30);
		tbRoupas.setBackground(new Color(240, 240, 240));
		tbRoupas.setSelectionBackground(new Color(254, 254, 254));
		tbRoupas.setShowVerticalLines(false);

		jScrollPane1.setOpaque(false);
		jScrollPane1.getViewport().setBorder(null);
		jScrollPane1.getViewport().setOpaque(false);

		// setColumnSizes(tbRoupas);
	}

	private void setColumnSizes(JTable table) {
		table.getColumnModel().getColumn(7).setMaxWidth(35); // ID
		//
		// table.getColumnModel().getColumn(1).setMinWidth(105); // CPF
		// table.getColumnModel().getColumn(1).setMaxWidth(105); // CPF
		//
		// table.getColumnModel().getColumn(2).setMinWidth(225); // CAR
		// table.getColumnModel().getColumn(2).setMaxWidth(225); // CAR
		//
		// table.getColumnModel().getColumn(3).setMinWidth(145); // PERIOD
		// table.getColumnModel().getColumn(3).setMaxWidth(145); // PERIOD
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		lbBack = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		tbRoupas = new javax.swing.JTable();
		jLabel1 = new javax.swing.JLabel();
		jLabel1.setForeground(Color.WHITE);
		jLabel1.setBackground(Color.BLACK);
		jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel1.setOpaque(true);

		setBackground(java.awt.Color.white);

		lbBack.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		lbBack.setIcon(new ImageIcon(TelaResultados.class.getResource("/images/back.png"))); // NOI18N
		lbBack.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				lbBackMouseClicked(evt);
			}
		});

		jLabel1.setFont(new Font("Gabriola", Font.PLAIN, 36)); // NOI18N
		jLabel1.setText("Dicas");
		jLabel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 15, 5,
				15));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		layout.setHorizontalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addContainerGap()
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addGroup(layout.createSequentialGroup()
							.addComponent(lbBack, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(jLabel1, GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE))
						.addGroup(layout.createSequentialGroup()
							.addGap(386)
							.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)))
					.addContainerGap())
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addContainerGap()
					.addGroup(layout.createParallelGroup(Alignment.LEADING, false)
						.addComponent(lbBack, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 364, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(59, Short.MAX_VALUE))
		);
		this.setLayout(layout);

	}// </editor-fold>//GEN-END:initComponents

	private void lbBackMouseClicked(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_lbBackMouseClicked
		PvsFrame.INSTANCE.home();
	}// GEN-LAST:event_lbBackMouseClicked
	private javax.swing.JLabel jLabel1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JLabel lbBack;
	private javax.swing.JTable tbRoupas;
	// End of variables declaration//GEN-END:variables}
}
